const Addr = require('../model/addr.model')
class addrSerivice{
    async createAddr(params){
        return await Addr.create(params)
        
    }
    async addressFindall(user_id){
        return await Addr.findAll({
            where:{
                user_id:user_id,
            },
            attributes:['id','phone','address','is_default']
        })
    }
    async updateAddress(id,data){
        try {
            
            return await Addr.update(data,{
                where:{id}
            })
        } catch (error) {
            console.log(error);
            
        }
    }
    async addrRemove(id){
        return await Addr.destroy({
            where:{
                id
            }

        }
        )
    }
    async updateDefaultAddr(user_id,id){
        await Addr.update({is_default:false},{
            where:{user_id}
        })
        return await Addr.update({is_default:true},{
            where:{id}
        })
    }
}
module.exports = new addrSerivice()